if (typeof T === 'undefined') require('../setup');

T('minus', function () {

  var t = function (minuend, subtrahend, expected) {
    T.assertEqual(expected, new Decimal(minuend).minus(subtrahend).valueOf());
  }

  Decimal.config({
    precision: 200,
    rounding: 4,
    toExpNeg: -9e9,
    toExpPos: 9e9
  });

  t(1, 0, '1');
  t(1, -0, '1');
  t(-1, 0, '-1');
  t(-1, -0, '-1');
  t(0, 1, '-1');
  t(0, -1, '1');
  t(-0, 1, '-1');
  t(-0, -1, '1');

  t(1, '0', '1');
  t(1, '1', '0');
  t(1, '-45', '46');
  t(1, '22', '-21');
  t(1, 0144, '-99');
  t(1, '0144', '-143');
  t(1, '6.1915', '-5.1915');
  t(1, '-1.02', '2.02');
  t(1, '0.09', '0.91');
  t(1, '-0.0001', '1.0001');
  t(1, '8e5', '-799999');
  t(1, '9E12', '-8999999999999');
  t(1, '1e-14', '0.99999999999999');
  t(1, '3.345E-9', '0.999999996655');
  t(1, '-345.43e+4', '3454301');
  t(1, '-94.12E+0', '95.12');
  t('0', 0, '0');
  t('0', '0', '0');
  t(3, -0, '3');
  t(9.654, 0, '9.654');
  t(0, '0.001', '-0.001');
  t(0, '111.1111111110000', '-111.111111111');
  t(-1, 1, '-2');
  t(-0.01, 0.01, '-0.02');
  t(54, -54, '108');
  t(9.99, '-9.99', '19.98');
  t('0.0000023432495704937', '-0.0000023432495704937', '0.0000046864991409874');
  t(100, 100, '0');
  t(-999.99, '0.01', '-1000');
  t('10', 4, '6');
  t('03.333', -4, '7.333');
  t(-1, -0.1, '-0.9');
  t(43534.5435, '0.054645', '43534.488855');
  t('99999', '1', '99998');

  t = function (minuend, subtrahend, expected, sd) {
    Decimal.precision = sd;
    T.assertEqual(expected, new Decimal(minuend).minus(subtrahend).valueOf());
  }
  t('1E-17', '1E-16', '-0.00000000000000009', 67);
  t('0.001', '1E-37', '0.00099999999999', 11);
  t('1E-35', '1E-15', '-0.00000000000000099999999999999999999', 72);
  t('1E-31', '0.01', '-0.0099999999999999999999999999999', 36);
  t('1E-20', '1E-30', '0.000000000000000000009999999999', 99);
  t('1E-20', '1E-34', '0.0000000000000000000099999999999999', 41);
  t('1E-37', '1E-14', '-0.0000000000000099999999999999999999999', 99);
  t('0.1', '1E-29', '0.09999999999999999999999999999', 53);
  t('1E-27', '1E-27', '0', 14);
  t('1E-33', '1E-28', '-0.000000000000000000000000000099999', 6);
  t('1E-16', '1E-9', '-0.0000000009999999', 74);
  t('1E-20', '1E-26', '0.00000000000000000000999999', 88);
  t('1E-14', '1E-32', '0.00000000000000999999999999999999', 68);
  t('1E-15', '1E-18', '0.000000000000000999', 46);
  t('1E-34', '1E-31', '-0.0000000000000000000000000000000999', 90);
  t('0.01', '0.0001', '0.0099', 27);
  t('1E-22', '0.01', '-0.0099999999999999999999', 62);
  t('1E-19', '0.1', '-0.0999999999999999999', 64);
  t('1E-40', '1E-12', '-0.0000000000009999999999999999999999999999', 98);
  t('1E-37', '1E-16', '-0.0000000000000000999999999999999999999', 82);
  t('0.1', '1E-11', '0.09999999999', 88);
  t('0.001', '1E-14', '0.00099999999999', 56);
  t('1E-14', '1E-31', '0.0000000000000099999999999999999', 42);
  t('0.00001', '1E-35', '0.0000099999999999999999999999', 23);
  t('0.000001', '1E-17', '0.00000099999999999', 19);
  t('1E-16', '1E-37', '0.0000000000000000999999999999999999999', 50);
  t('1E-18', '1E-15', '-0.000000000000000999', 70);
  t('1E-27', '1E-30', '0.000000000000000000000000000999', 76);
  t('0.000001', '1E-35', '0.00000099999999999999999999999999999', 40);
  t('1E-20', '1E-27', '0.000000000000000000009999999', 32);
  t('0.1', '1E-25', '0.0999999999999999999999999', 75);
  t('1E-33', '1E-19', '-0.000000000000000000099999999999999', 15);
  t('1E-7', '1E-34', '0.0000000999999999999999999999999999', 96);
  t('1E-32', '1E-35', '0.00000000000000000000000000000000999', 4);
  t('0.1', '1E-31', '0.0999999999999999999999999999999', 31);
  t('1E-21', '1E-12', '-0.00000000000099999', 5);
  t('1E-38', '0.1', '-0.09999999999999999999', 19);
  t('1E-25', '0.1', '-0.0999999999999999999999999', 83);
  t('0.001', '1E-21', '0.000999999999999999999', 100);
  t('1E-10', '0.1', '-0.0999999999', 58);
  t('1E-18', '1E-39', '0.000000000000000000999999999999999999999', 84);
  t('1E-16', '1E-39', '0.00000000000000009999999999999999999', 19);
  t('1E-24', '1E-36', '0.000000000000000000000000999999999999', 25);
  t('1E-10', '1E-39', '0.000000000099999999999999999999999999999', 67);
  t('1E-24', '1E-30', '0.00000000000000000000000099', 2);
  t('1E-23', '1E-37', '0.0000000000000000000000099999999999999', 55);
  t('1E-27', '1E-39', '0.000000000000000000000000000999999999999', 27);
  t('1E-28', '1E-27', '-0.0000000000000000000000000009', 86);
  t('0.000001', '1E-16', '0.0000009999999999', 35);
  t('1E-25', '0.0001', '-0.0000999999999999999999999', 54);
  t('1E-12', '0.00001', '-0.000009999999', 50);
  t('0.1', '1E-23', '0.0999999999', 9);
  t('0.01', '1E-10', '0.0099999999', 52);
  t('0.1', '1E-12', '0.09999', 4);
  t('1E-26', '1E-37', '0.0000000000000000000000000099999999999', 70);
  t('1E-23', '1E-14', '-0.00000000000000999999999', 56);
  t('1E-21', '0.0001', '-0.000099999999999999999', 39);
  t('1E-10', '0.1', '-0.0999999999', 26);
  t('1E-17', '0.01', '-0.00999999999999999', 20);
  t('1E-26', '1E-21', '-0.00000000000000000000099999', 85);
  t('0.000001', '1E-33', '0.000000999999999999999999999999999', 90);
  t('1E-27', '0.1', '-0.099999999999999999999999999', 84);
  t('1E-21', '1E-18', '-0.000000000000000000999', 88);
  t('1E-16', '1E-16', '0', 56);
  t('1E-37', '0.000001', '-0.0000009999999999999999999999999999999', 33);
  t('1E-20', '1E-22', '0.0000000000000000000099', 51);
  t('1E-16', '1E-30', '0.000000000000000099999999999999', 20);
  t('1E-22', '1E-10', '-0.0000000000999999999999', 87);
  t('1E-11', '1E-20', '0.00000000000999999999', 47);
  t('0.1', '1E-24', '0.099999999999999999999999', 46);
  t('1E-25', '0.001', '-0.0009999999999999999999999', 42);
  t('1E-15', '1E-37', '0.00000000000000099999999999', 11);
  t('1E-22', '0.001', '-0.0009999999999999999999', 81);
  t('1E-24', '1E-12', '-0.000000000000999999999999', 20);
  t('1.000000', '18105728986041761640887595533283120477.2742082541073753474', '-18100000000000000000000000000000000000', 4);
  t('0.99999998878183120416824285037203', '38327.8407', '-38326.8407000112181687958317', 27);
  t('0.9999999999999999999999999996779494408046302584202610482', '530770914537012205776892173.865394333047000705228144653463710904', '-530770914537012205776892172.8653943330470007052281446537857614631953697415797389518', 92);
  t('1.000154688825648481267644205561160017273389804317525860318979525925354', '5590.1166644928260', '-5589.1165098040003515187323557944388', 35);
  t('0.99999999999006027143696724994249662', '88359515632902648.759516639917666812111537547', '-88359515632902600', 15);
  t('1.0000000000', '53.0721765572571058497526522442', '-52.0721765572571058497526522442', 68);
  t('1.0000000000000000010868737982065976552678875918917937663867883830744', '72274249298653961307161266.2429171261996071156986500328106121752', '-72274249298653961307161265.2429171261996071146117762346040145199321124081082062336132116', 87);
  t('1.00000000000000000000081253348145920781026085647520801897170982656182514222627649830571537940570097', '34180955261225283278.9546214472426960215969277072', '-34180955261225283277.954621447242696021596115173718540792189739143524791981028290173438174857773723', 98);
  t('0.99999999999999999999999999999999999998756496998614330743704048912', '36423078435.49585469762969072900556033', '-36423078434.49585469762969072900556033000000000001243503', 56);
  t('0.99999999999999999999999999999815156221279091250236161202515555239214607133', '184535429818126810905.866146730925744980274670738002788577', '-184535429818126810904.866146730925744980274670738004637014787209087497', 69);
  t('1.10455706926852759636854514325898495936688404757420394401166868002', '35601365816445214252.5525881378161872928170', '-35601365816445214251.44803106854765969644845485674101504063311595242579605598833131998', 98);
  t('0.9999999999380984950253', '83972321187501515671178201780968.114223326', '-83972321187501515670000000000000', 19);
  t('1.00000000000000000000000000000002230745989026902237', '5182909643868660181.616326849296578520834', '-5182909643868660180.61632684929657852083399999999997769254010973097763', 74);
  t('1.00000000000000000000000000000000017890501993570751536367804830406693776445', '7596063323395135740831786963557300.828122807129946719956', '-7596063323395135740831786963557299.82812280712994671995599999999999982109498006429248463', 87);
  t('0.99999999997144379431778592551299579284817269428143146335310624910486', '5744510660347753705135441208927833216328.435064197579250286979352170', '-5744510660347753705135441208927833216327.435064197607806492661566244487004', 73);
  t('1.0000000000000000000', '5966.1758018', '-5965.1758018', 58);

  t('606.254575304', '10913610393350.2606', '-10913610392744.006024696', 37);
  t('42885995.8922914272', '706475.796938411', '42170000', 4);
  t('6052717165.1446', '65455223170949076520.8060582718286379316', '-65455223164896300000', 15);
  t('5955452.7441572243480999', '916606845979019189.694793932', '-916606845973063000', 15);
  t('2571182.9104', '5112317485037139357.0326821757855538364', '-5112317485034568174.12228217578555383', 36);
  t('33777941893928234.1403399701827010', '4007790318278125722.91052580512126369', '-3000000000000000000', 1);
  t('6409343803262.388', '823497316.0', '6408520305946.388', 38);
  t('35811.99', '6730744506562.519', '-6000000000000', 1);
  t('29074997967.4033077914', '566332182964.6602808', '-537250000000', 5);
  t('9529.144771387', '8895131556.883', '-8895122027.738228613', 34);
  t('1376622519151175.50445', '75251508328.9053133011113', '1376547267642846.5991366988887', 40);
  t('7062679212073143326888924001163.02786', '670367382193775796879309.97397127870279732280890295', '7062678541705761133000000000000', 19);
  t('269622299212099.5658', '67080856574410241738.2', '-67080586952111029638.6342', 43);
  t('347539.651654349', '999164349246243097554653376.101753100580453', '-999164349246243000000000000', 16);
  t('589630075341582712237298018007.626791554398075374457001806', '37072203775488.5460924874', '589630075341582675165094242519.080699066998075374457001806', 80);
  t('239797538.62924219574590', '62.7179', '239797475.9113421957459', 29);
  t('68389708692892364357038.550642618', '346589125.87181', '68389708692892017767912.678832618', 74);
  t('22366800802617651725451014763352512558.88384367', '56706199621325498.77362822019', '22366800802617651725394308563731187060.11021544981', 77);
  t('5501088.6084944677846990708389945743093', '664927.656419331398418627625297930574', '4836160.9520751363862804432136966437353', 53);
  t('999909783662285281933157327721667.775471879628', '2795909691798312648666149730968954.548860473478014471571999555369104559', '-1795999908136027366732992403247280', 33);
  t('3761160947240340619655699804028514166.1545031706631', '90008594170211932230610878657643955.0766771120853201398452422803203', '3671000000000000000000000000000000000', 4);
  t('55148738462073723350464458331198071161.324235957257244236', '890533822519200952605943.67027149110407422724883', '55148738462072832816641939130245465210', 37);
  t('5527758.208579037564171467506', '57746543998576.5', '-57746538470818.291420962435828532494', 57);

  Decimal.toExpNeg = Decimal.toExpPos = 0;

  t('-14434824877681671252494.50', '-4744180884604619155005023739354631157756385352850463825687419180.317893158', '4.744180884604619155005023739354631157756370918025586144016e+63', 58);
  t('4.511087857625328082657257239895665113144003584405761127577260517484874613e+778771121', '1.8325842443473932072e-59442002', '4.511087857625328082657257239895665113144003584405761127577260517484874612999999999999999e+778771121', 88);
  t('-688837253042614877399.5', '-3.632441039346975825180266180783847897335359529888336884091855e+188507', '3.6324410393469758251802661807838478973353595298883368840918549999999999999999999999e+188507', 83);
  t('7.43404688761493575549516036492094029880287e-26712037', '-7.9066293190521765772848055594328963843287417065639566213443958915377769052389889e+928963854', '7.90662931905217657728480555943289638432874170656395662134439e+928963854', 60);
  t('-4.320626740890915234398134986114517e+94658', '2.78894990560963181013521759e+8249', '-4.32062674089091523439813498e+94658', 27);
  t('-3.95785198444775477048e-46', '-6.870396030942305e-7108', '-3.957851984447754770479999999999999999999999999999999999999999999999999999e-46', 73);
  t('-7.17914921169565067656826325978347627539814084292339438679298679106912228033991102060926370758854e-7922150', '7.149725093137932026784009177225420e+497084531', '-7.14972509313793202678400917722542e+497084531', 65);
  t('8.356458499777e-30', '-4.8e-10939393', '8.356458499777e-30', 40);
  t('5.991948215377e-6123814', '6.38169244547e-151999802', '5.991948e-6123814', 7);
  t('-5.21392008878352879914684467839557603e-6383', '7.9128406143023651297161503149801950528574678665327896050715374145940581e+68652', '-7.91284e+68652', 7);
  t('-6.2846594717691810204240002443373127012520917569388241491889161091457255e+405', '8.0153128400211520487097219622809800495350464749634911270946865114372247349824051499281e-403780935', '-6.284659471769181020424000244337312701252e+405', 41);
  t('5.04188783533720818821892800831885659358875702648575435572892191640197223326922385205881e+94', '-4.044799176079958739979061829854269217248659863992017958880957143157173214518526499880140332437e-114', '5.04188783533720818821892800831885659358875702648575435572892191640197223326922385205881e+94', 93);
  t('-3.32941405604212020e-471060', '5.8742682933034054748993473533381157135243211041287576477331104705911641772138481682906049360e-6416', '-5.87426829330340547489934735333811571352432110412875764773311047059116417721384e-6416', 78);
  t('5.806100701116837194078609598286654001909211492267547200e-6351', '-3.1322555058724231886103050203444286e+8361722', '3.1322555058724231886103050203444286e+8361722', 89);
  t('6.858541567594014583569e-92403457', '932344125683735556729917290084013738442958.911626146652618624368048421976479', '-9.323441256837355567e+41', 19);
  t('-7.4825478541105716433040812574e-2957384', '-8933987726393636136642392373893254836880610561986804046816378730701943482730.285263', '8.93398772639363613664239237389325483688061056198680404681637873070194348e+75', 72);
});
